﻿/*JumbotCmsV4
作者:随风缘
本文件非单独运行，需要引用/_data/SysConfig.js和/_libs/jquery-min.js
*/
document.write("<script type=\"text\/javascript\" src=\"" + site.Dir + "_data/json/_site.js\"><\/script>");
document.write("<script type=\"text\/javascript\" src=\"" + site.Dir + "_data/json/_modules.js\"><\/script>");
var jcms$$HintUrl		= site.Dir + "style/hint/";
var jcms$$DialogUrl		= site.Dir + "style/dialog/";
/*------------------------------------------------------------------*/
function $$(el)
{
	if(typeof el=='string')
		return document.getElementById(el);
	else if(typeof el=='object')
		return el;
}
var JumbotCms=new Object();
JumbotCms.Cookie={
	set:function(name,value,expires,path,domain){
		if(typeof expires=="undefined"){
			expires=new Date(new Date().getTime()+24*3600*100);
		}
		document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"; path=/")+((domain)?";domain="+domain:"");
	},
	get:function(name){
		var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
		if(arr!=null){
			return unescape(arr[2]);
		}
		return null;
	},
	clear:function(name,path,domain){
		if(this.get(name)){
			document.cookie=name+"="+((path)?"; path="+path:"; path=/")+((domain)?"; domain="+domain:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		}
	}
};
//追加/删除事件
JumbotCms.Event={
	add:function(obj, evType, fn){
		if (obj.addEventListener){obj.addEventListener(evType, fn, false);return true;}
		else if (obj.attachEvent){var r = obj.attachEvent("on"+evType, fn);return r;}
		else {return false;}
	},
	remove:function(obj, evType, fn, useCapture){
		if (obj.removeEventListener){obj.removeEventListener(evType, fn, useCapture);return true;}
		else if (obj.detachEvent){var r = obj.detachEvent("on"+evType, fn);return r;}
		else {alert("Handler could not be removed");}
	}
};
//追加onload事件
JumbotCms.addOnloadEvent=function(fnc) {
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "load", fnc, false );
	else if ( typeof window.attachEvent != "undefined" )
	{
		window.attachEvent( "onload", fnc );
	}
	else
	{
		if ( window.onload != null )
		{
			var oldOnload = window.onload;
			window.onload = function (e) {
				oldOnload(e);
				window[fnc]();
			};
		} else
			window.onload = fnc;
	}
};
JumbotCms.isFunction=function(variable) {
	return typeof variable == 'function' ? true : false;
};
JumbotCms.isUndefined=function(variable) {
	return typeof variable == 'undefined' ? true : false;
};
JumbotCms.Length=function(variable) {
	var len = 0;
	var val = variable;
	for (var i = 0; i < val.length; i++) 
	{
		if (val.charCodeAt(i) >= 0x4e00 && val.charCodeAt(i) <= 0x9fa5){ 
			len += 2;
		}else {
			len++;
		}
	}
	return len;
};
JumbotCms.Eval=function(data) {
	JumbotCms.Loading.hide();
	try {
		eval(data);
	}
	catch(e) {
		alert(data);	
	}
};
/////////////////////////////
//弹出提示框
/////////////////////////////
JumbotCms.Alert=function(errstr, success, returnFunc){
	var oDialog = new jcms$$Dialog('2', '', 360, 180, success, true);
	oDialog.init();
	oDialog.event(errstr,'');
	if (returnFunc == null)
		oDialog.button('dialogSubmit', '');
	else
		oDialog.button('dialogSubmit', returnFunc);
};
/////////////////////////////
//弹出确认框
//例如:
//1、JumbotCms.Confirm("是否操作", act, null) //函数不加()
//2、JumbotCms.Confirm("是否操作", "alert('yes')", "alert('no')")
/////////////////////////////
JumbotCms.Confirm=function(errstr, returnSubmitFunc, returnCancelFunc)
{
	var oDialog = new jcms$$Dialog('2', '', 360, 180, "warning", true);
	oDialog.init();
	oDialog.event(errstr,'');
	oDialog.button('dialogSubmit', returnSubmitFunc);
	if (returnCancelFunc == null)
		oDialog.button('dialogCancel', '');
	else
		oDialog.button('dialogCancel', returnCancelFunc);
};
/////////////////////////////
//弹出模拟窗口
/////////////////////////////
JumbotCms.Popup={
	show:function(url, width, height, showCloseBox, showTitle, returnFunc)
	{
		new jcms$$Dialog().reset();
		if(showTitle==null) showTitle="&nbsp;";
		var oDialog = new jcms$$Dialog('2', showTitle, width, height, null, showCloseBox);
		if (url.indexOf("?") == -1)
			oDialog.open(url+"?windowCode="+(new Date().getTime()), returnFunc, "auto");
		else
			oDialog.open(url+"&windowCode="+(new Date().getTime()), returnFunc, "auto");
	},
	hide:function(callReturnFunc){
		new jcms$$Dialog().reset(callReturnFunc);
	}
};
/////////////////////////////
//弹出加载层
/////////////////////////////
JumbotCms.Loading={
	show:function(msgstr, width, height)
	{
		if(width==null) width=280;
		if(height==null) height=100;
		var oDialog = new jcms$$Dialog('0', '友情提示', width, height, null, false);
		oDialog.init(true);
		oDialog.html("<div style='text-align:center;padding-top:20px;'>"+msgstr+"<br /><br /><img src='" + jcms$$DialogUrl + "loading.gif' align='absmiddle'></div>");
	},
	hide:function(callReturnFunc){
		new jcms$$Dialog().reset(callReturnFunc);
	}
};
////////////////////////////////////////////////////////////////////////////////////////////
//提示层
////////////////////////////////////////////////////////////////////////////////////////////
JumbotCms.Hint={
	show:function(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
	{
		var oHint = new jcms$$Hint(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset);
		oHint.show();
	},
	hide:function(){
		new jcms$$Hint().hide();
	}
}
JumbotCms.Event.add(window,"load",jcms$$OperatorPlus);
JumbotCms.Event.add(window,"scroll",jcms$$OperatorPlus);
JumbotCms.Event.add(window,"resize",jcms$$OperatorPlus);
////////////////////////////////////////////////////////////////////////////////////////////

var jcms$$HideSelects              = false;
var jcms$$DialogIsShown            = false;
var jcms$$WindowMask               = null;
////////////////////////////////////////////////////////////////////////////////////////////
//以下为弹出窗口的类
////////////////////////////////////////////////////////////////////////////////////////////
function jcms$$Dialog(styletype, title, width, height, iswhat, showCloseBox){
	//半透明边框宽度
	var shadowBorderBoth=0;
	var oWidth = width;
	var oHeight = height;
	if(oWidth<0 || oWidth>jcms$$GetViewportWidth()-15)
	{
		oWidth=jcms$$GetViewportWidth()-15;
		shadowBorderBoth = 0;
	}
	if(oHeight<0 || oHeight>jcms$$GetViewportHeight()-35)
	{
		oHeight=jcms$$GetViewportHeight()-35;
		shadowBorderBoth = 0;
	}
	var sTitle = "友情提示";
	if (iswhat == "0")
		sTitle = "错误提示";
	else if (iswhat == "1")
		sTitle = "成功提示";
	else
		if (title!='') sTitle = title;
	var src = "";
	var path = jcms$$DialogUrl + styletype + "/";
	var gReturnFunc;
	var gReturnVal = null;
	var sButtonFunc = '<input id="dialogSubmit" class="dialogSubmit' + styletype + '" type="button" value="确 认" onclick="new jcms$$Dialog().reset();" /> <input id="dialogCancel" class="dialogCancel' + styletype + '" type="button" value="取 消" onclick="new jcms$$Dialog().reset();" />';
	var sClose = '';
	if (showCloseBox == null || showCloseBox == true)
		sClose = '<img alt="关闭" style="cursor:pointer;" id="dialogBoxClose" onclick="new jcms$$Dialog().reset();" src="' + path + 'dialogCloseOut.gif" border="0" onmouseover="this.src=\'' + path + 'dialogCloseOver.gif\';" onmouseout="this.src=\'' + path + 'dialogCloseOut.gif\';" align="absmiddle" />';
	var sSuccess = '';
	if (iswhat != null)
		sSuccess = '<td width="80" align="center" valign="middle"><img id="dialogBoxFace" class="dialogBoxFace' + styletype + '" src="' + path + iswhat + '.gif" valign="absmiddle" /></td>';
	else
		sSuccess = '<td width="80" align="center" valign="middle"><img id="dialogBoxFace" class="dialogBoxFace' + styletype + '" src="warning.gif" valign="absmiddle" /></td>';
	var sBody = '\
		<table id="dialogBodyBox" class="dialogBodyBox' + styletype + '" border="0" align="center" cellpadding="0" cellspacing="0" width="100%" height="100%" >\
			<tr height="' + (oHeight - 60) + '">\
				<td width="10"></td>' + sSuccess + '<td id="dialogMsg" class="dialogMsg' + styletype + '"></td>\
				<td width="10"></td>\
			</tr>\
			<tr height="30"><td id="dialogFunc" class="dialogFunc' + styletype + '" colspan="4">' + sButtonFunc + '</td></tr>\
		</table>\
	';
	var sBox = '\
		<div style="display:none;" id="dialogBox" class="dialogBox' + styletype + '">\
			<div id="dialogTitleDiv" class="dialogTitleDiv' + styletype + '" style="width:' + oWidth + 'px;">\
				<span id="dialogBoxTitle" class="dialogBoxTitle' + styletype + '">' + sTitle + '</span>\
				<span id="dialogBoxClose" class="dialogBoxClose' + styletype + '">' + sClose + '</span>\
			</div>\
			<div id="dialogHeight" style="width:' + oWidth + 'px;height:' + oHeight + 'px;">\
				<div id="dialogBody" class="dialogBody' + styletype + '" style="height:' + oHeight + 'px;">' + sBody + '</div>\
			</div>\
		</div>\
		<div id="dialogBoxShadow" style="display:none;"></div>\
	';
	this.init = function(_showTitleBar){
		document.body.oncontextmenu=function(){return false;};
		document.body.onselectstart=function(){return false;};
		document.body.ondragstart=function(){return false;};
		document.body.onsource=function(){return false;};
		$$('dialogCase') ? $$('dialogCase').parentNode.removeChild($$('dialogCase')) : function(){};
		$$('windowMask') ? $$('windowMask').parentNode.removeChild($$('windowMask')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		oDiv.innerHTML = sBox;
		document.body.appendChild(oDiv);
		var oMask = document.createElement('div');
		oMask.id = 'windowMask';
		document.body.appendChild(oMask);
		jcms$$WindowMask = $$("windowMask");
		jcms$$WindowMask.style.display="block";
		var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
		if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
			jcms$$HideSelects = true;
		}
		if (jcms$$HideSelects == true) {
			HideSelectBoxes();
		}
		if (_showTitleBar == true || _showTitleBar == null)
			$$("dialogTitleDiv").style.display = "block";
		else
			$$("dialogTitleDiv").style.display = "none";
		jcms$$OperatorPlus();
	}
	//this.show = function(){$$('dialogBox') ? function(){} : this.init();jcms$$DialogIsShown=true;this.middle('dialogBox');}
	this.show = function(){$$('dialogBox') ? function(){} : this.init();jcms$$DialogIsShown=true;this.middle('dialogBox');this.shadow();this.middle('dialogBoxShadow');jcms$$OperatorPlus();}
	this.html = function(_sHtml){
		this.show();
		$$('dialogBody').innerHTML = _sHtml;
	}
	this.button = function(_sId, _sFuc){
		if($$(_sId)){
			$$(_sId).style.display = '';
			if($$(_sId).addEventListener){
				if($$(_sId).act){$$(_sId).removeEventListener('click', function(){eval($$(_sId).act);}, false);}
				$$(_sId).act = _sFuc;
				$$(_sId).addEventListener('click', function(){eval(_sFuc);this.reset();}, false);
			}else{
				if($$(_sId).act){$$(_sId).detachEvent('onclick', function(){eval($$(_sId).act);});}
				$$(_sId).act = _sFuc;
				$$(_sId).attachEvent('onclick', function(){eval(_sFuc);});
			}
		}
	}
	this.shadow = function(){
		if(shadowBorderBoth>0){
			var oShadow = $$('dialogBoxShadow');
			var oDialogDiv = $$('dialogBox');
			oShadow.style.position = "absolute";
			oShadow.style.background = "#000";
			oShadow.style.display = "";
			oShadow.style.opacity = "0.25";
			oShadow.style.filter = "alpha(opacity=25)";
			oShadow.style.width = (oDialogDiv.offsetWidth + shadowBorderBoth)+"px";
			oShadow.style.height = (oDialogDiv.offsetHeight + shadowBorderBoth)+"px";
		}
	}
	this.open = function(_sUrl, _returnFunc, _sMode){
		this.show();
		gReturnFunc = _returnFunc;
		//if(!_sMode || _sMode == "no" || _sMode == "yes"){
			$$("dialogBody").innerHTML = "<iframe id='dialogFrame' width='" + oWidth + "' height='" + oHeight + "' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='" + _sMode + "'></iframe>";
			$$("dialogFrame").src = _sUrl;
		//}
	}
	this.reset = function(callReturnFunc){$$('dialogCase') ? this.dispose(callReturnFunc) : function(){};}
	this.dispose = function(callReturnFunc){
		jcms$$DialogIsShown = false;
		document.body.oncontextmenu=function(){return true;};
		document.body.onselectstart=function(){return true;};
		document.body.ondragstart=function(){return true;};
		document.body.onsource=function(){return true;};
		$$('dialogCase').parentNode.removeChild($$('dialogCase'));
		$$('windowMask').parentNode.removeChild($$('windowMask'));
		jcms$$WindowMask=null;
		if (callReturnFunc == true && gReturnFunc != null) {
			gReturnVal = window.dialogFrame.returnVal;
			window.setTimeout('gReturnFunc(gReturnVal);', 1);
		}
		if (jcms$$HideSelects == true) {
			ShowSelectBoxes();
			jcms$$HideSelects = false;
		}
		//$$('dialogBoxShadow').style.display = "none";
	}
	this.event = function(_sMsg, _sSubmit, _sCancel, _sClose){
		this.show();
		$$('dialogFunc').innerHTML = sButtonFunc;
		$$('dialogBoxClose').innerHTML = sClose;
		$$('dialogBodyBox') == null ? $$('dialogBody').innerHTML = sBody : function(){};
		$$('dialogMsg') ? $$('dialogMsg').innerHTML = _sMsg  : function(){};
		_sSubmit ? this.button('dialogSubmit', _sSubmit) | $$('dialogSubmit').focus() : $$('dialogSubmit').style.display = "none";
		_sCancel ? this.button('dialogCancel', _sCancel) : $$('dialogCancel').style.display = "none";
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
	}
	this.set = function(_oAttr, _sVal){
		var oDialogDiv = $$('dialogBox');
		var oHeight = $$('dialogHeight');
		if(_sVal != ''){
			switch(_oAttr){
				case 'title':
					$$('dialogBoxTitle').innerHTML = _sVal;
					title = _sVal;
					break;
				case 'width':
					oDialogDiv.style.width = _sVal;
					width = _sVal;
					this.middle('dialogBox');
					this.shadow();
					this.middle('dialogBoxShadow');
					jcms$$OperatorPlus();
					break;
				case 'height':
					oHeight.style.height = _sVal;
					height = _sVal;
					this.middle('dialogBox');
					this.shadow();
					this.middle('dialogBoxShadow');
					jcms$$OperatorPlus();
					break;
				case 'src':
					if(parseInt(_sVal) > 0){
						$$('dialogBoxFace') ? $$('dialogBoxFace').src = path + _sVal + '.png' : function(){};
					}else{
						$$('dialogBoxFace') ? $$('dialogBoxFace').src = _sVal : function(){};
					}
					src = _sVal;
					break;
				case 'url':
					this.open(_sVal);
					break;
			}
		}
	}
	this.middle = function(_sId){	
		var theWidth;
		var theHeight;
		if (document.documentElement && document.documentElement.clientWidth) { 
			theWidth = document.documentElement.clientWidth+document.documentElement.scrollLeft*2;
			theHeight = document.documentElement.clientHeight+document.documentElement.scrollTop*2; 
		} else if (document.body) { 
			theWidth = document.body.clientWidth;
			theHeight = document.body.clientHeight; 
		}else if(window.innerWidth){
			theWidth = window.innerWidth;
			theHeight = window.innerHeight;
		}
		$$(_sId).style.display = '';
		$$(_sId).style.position = "absolute";
		$$(_sId).style.left = (theWidth / 2) - ($$(_sId).offsetWidth / 2)+"px";
		if(document.all||$$("user_page_top")){
			$$(_sId).style.top = (theHeight / 2 + document.body.scrollTop) - ($$(_sId).offsetHeight / 2)+"px";
		}else{
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
			var sTop = -80 + (sClientHeight / 2 + sScrollTop) - ($$(_sId).offsetHeight / 2);
			$$(_sId).style.top = (theHeight / 2 + document.body.scrollTop) - ($$(_sId).offsetHeight / 2)+"px";
		}
	}
	BtnOver=function(obj,path){obj.style.backgroundImage = "url("+path+"button2.gif)";}
	BtnOut=function(obj,path){obj.style.backgroundImage = "url("+path+"button1.gif)";}
	ShowSelectBoxes=function(){var x = document.getElementsByTagName("SELECT");for (i=0;x && i < x.length; i++){x[i].style.visibility = "visible";}}
	HideSelectBoxes=function(){var x = document.getElementsByTagName("SELECT");for (i=0;x && i < x.length; i++) {x[i].style.visibility = "hidden";}}

}
///////////////////////////////////////////////////////////////////////////
function jcms$$OperatorPlus() {
	if (jcms$$DialogIsShown == true) {
		var oDialogDiv = $$("dialogBox");
		var oShadow = $$("dialogBoxShadow");
		var oWidth = oDialogDiv.offsetWidth;
		var oHeight = oDialogDiv.offsetHeight;
		var theBody = document.getElementsByTagName("BODY")[0];
		var scTop = parseInt(jcms$$GetScrollTop(),10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		var fullHeight = jcms$$GetViewportHeight();
		var fullWidth = jcms$$GetViewportWidth();
		oDialogDiv.style.top = (scTop + ((fullHeight - oHeight) / 2)) + "px";
		oDialogDiv.style.left = (scLeft + ((fullWidth - oWidth) / 2)) + "px";
		oShadow.style.top = (scTop + ((fullHeight - oShadow.offsetHeight) / 2)) + "px";
		oShadow.style.left = (scLeft + ((fullWidth - oShadow.offsetWidth) / 2)) + "px";
		if (jcms$$WindowMask != null) {
			var popHeight = theBody.scrollHeight;
			var popWidth = theBody.scrollWidth;
			if (fullHeight > theBody.scrollHeight) popHeight = fullHeight;
			if (fullWidth > theBody.scrollWidth) popWidth = fullWidth;
			jcms$$WindowMask.style.height = popHeight + "px";
			jcms$$WindowMask.style.width = popWidth + "px";
		}
	}
}
function jcms$$GetViewportHeight() {
	if (window.innerHeight!=window.undefined)//FF
	{
		return window.innerHeight;
	}
	if (document.compatMode=='CSS1Compat')//IE
	{
		return document.documentElement.clientHeight;
	}
	if (document.body)//other
	{
		return document.body.clientHeight; 
	}
	return window.undefined; 
}
function jcms$$GetViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined)//FF
	{
		//return window.innerWidth-offset; 
		return window.innerWidth; 
	}
	if (document.compatMode=='CSS1Compat')//IE
	{
		return document.documentElement.clientWidth; 
	}
	if (document.body)//other
	{
		return document.body.clientWidth; 
	}
	return window.undefined; 
}
function jcms$$GetScrollTop() {
	if (self.pageYOffset){return self.pageYOffset;}
	else if (document.documentElement && document.documentElement.scrollTop){return document.documentElement.scrollTop;}
	else if (document.body){return document.body.scrollTop;}
}
function jcms$$GetScrollLeft() {
	if (self.pageXOffset){return self.pageXOffset;}
	else if (document.documentElement && document.documentElement.scrollLeft){return document.documentElement.scrollLeft;}
	else if (document.body){return document.body.scrollLeft;}
}
function jcms$$SetDialogTitle(){
	if(window.document.title!=""){
		try {
			$$('dialogBoxTitle').innerHTML = window.document.title;
		}
		catch(e) {
			try {
				parent.$$('dialogBoxTitle').innerHTML = window.document.title;
			}
			catch(e) {
			}	
		}
	}
}
function jcms$$SetDialogSize(w,h){
	try {
		if(w>0) $$('dialogBox').style.width = w;
		if(h>0) $$('dialogHeight').style.height = h;
		jcms$$OperatorPlus();
	}
	catch(e) {
		try {
			if(w>0) parent.$$('dialogBox').style.width = w;
			if(h>0) parent.$$('dialogHeight').style.height = h;
			parent.jcms$$OperatorPlus();
		}
		catch(e) {
		}	
	}	
}
//提示层类
function jcms$$Hint(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
{
	var path = jcms$$HintUrl;
	var imageLeft = path+'commandbg1.gif';
	var imageRight = path+'commandbg2.gif';
	if((showtype==null)||(showtype =="")) 
		showtype = "up";
	if(showtype=="down"){
		imageLeft = path+'commandbg3.gif';
		imageRight = path+'commandbg4.gif';
	}
	this.show = function() {
		this.init();
		var p = getposition(obj);
		$$('hintIframe').style.height= objheight + "px";
		$$('hintInfo').innerHTML = info;
		$$('hintSpan').style.display='block';
		if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
			$$('hintSpan').style.top=p['y']+parseInt(objtopfirefoxoffset)+"px";
		else
		{
			if(objtopoffset == 0)
			{ 
				if(showtype=="up")
				{
				 	$$('hintSpan').style.top=(p['y'] - $$('hintInfo').offsetHeight - 32)+"px";
				}
				else
				{
				 	$$('hintSpan').style.top=(p['y'] + obj.offsetHeight + 1)+"px";
				}
			}
			else
				$$('hintSpan').style.top=(p['y']+objtopoffset)+"px";
		}
		$$('hintSpan').style.left=(p['x']+objleftoffset)+"px";
	}
	//隐藏提示层
	this.hide = function() {
		$$('hintSpan').style.display='none';
	}
	function getposition(obj)
	{
		var r = new Array();
		r['x'] = obj.offsetLeft;
		r['y'] = obj.offsetTop;
		while(obj = obj.offsetParent)
		{
			r['x'] += obj.offsetLeft;
			r['y'] += obj.offsetTop;
		}
		return r;
	}
	this.init = function(){
		$$('hintSpan') ? $$('hintSpan').parentNode.removeChild($$('hintSpan')) : function(){};
		var hintObj=document.createElement("span");
		hintObj.setAttribute("id","hintSpan");
		hintObj.style.position="absolute";
		hintObj.style.display="none";
		var sBody = '<div id="hintDiv">\
				<p><img src="'+imageLeft+'" /></p>\
				<div class="hintmessagetext"><img id="hintdot" src="'+path+'dot.gif" /><span id="hintInfo" ></span></div>\
				<p><img src="'+imageRight+'" /></p>\
			</div>\
			<iframe id="hintIframe" frameborder="0" scrolling="no"></iframe>\
		';
		hintObj.innerHTML=sBody;
		document.body.appendChild(hintObj);
	}
}
////////////////////////////////////////////////////////////////////////////////////////////
function jcms$$SetUrlRefresh(url)
{
	if(url.indexOf("?") > 0)
    		return url+"&t="+(new Date().getTime());   
	else
    		return url+"?t="+(new Date().getTime());   
}


/*获取Cookies的值*/
function ReadCookie(name)
{
    var dc = document.cookie ;
    var start1 = dc.indexOf(name + "=");
    if (start1== -1)
    {
        return "";
    }
    else
    {
        start=dc.indexOf("=",start1)+1;
        var end = dc.indexOf(";",start);
        if (end==-1)
        {
         end=dc.length;
        }
         var value=unescape(dc.substring(start,end));
         if (value==null)
         {
            return ""
         }
         else
         {
           return  value ;
         }
     }
}
/*HTML标签小写*/
function HTML2LowerCase(html)
{
	return html.replace(/(<\/?)([a-z\d\:]+)((\s+.+?)?>)/gi,function(s,a,b,c){return a+b.toLowerCase()+c;});
}
/*获取指定字符串的长度*/
function GetLength(id)
{
	var srcjo = $("#"+id);
	sType = srcjo.get(0).type;
	var len = 0;
	switch(sType)
	{
		case "text":
		case "hidden":
		case "password":
		case "textarea":
		case "file":
			var val = srcjo.val();
			for (var i = 0; i < val.length; i++) 
			{
				if (val.charCodeAt(i) >= 0x4e00 && val.charCodeAt(i) <= 0x9fa5){ 
					len += 2;
				}else {
					len++;
				}
			}
			break;
		case "checkbox":
		case "radio": 
			len = $("input[@type='"+sType+"'][@name='"+srcjo.attr("name")+"'][@checked]").length;
			break;
		case "select-one":
			len = srcjo.get(0).options ? srcjo.get(0).options.selectedIndex : -1;
			break;
		case "select-more":
			break;
	}
	return len;
}
function InsertUnit(text, obj) {
	if(!obj) {
		obj = 'jstemplate';
	}
	var o = document.getElementById(obj);
	o.focus();
	if(!JumbotCms.isUndefined(o.selectionStart)) {
		var opn = o.selectionStart + 0;
		o.value = o.value.substr(0, o.selectionStart) + text + o.value.substr(o.selectionEnd);
	} else if(document.selection && document.selection.createRange) {
		var sel = document.selection.createRange();
		sel.text = text.replace(/\r?\n/g, '\r\n');
		//sel.moveStart('character', -strlen(text));
	} else {
		o.value += text;
	}
}
function JoinSelect(selectName)
{
	var selectIDs="";
	$("input[@name='" + selectName + "']").each(function(){
   		if($(this).attr("checked")==true){
			if(selectIDs=="")
    				selectIDs = $(this).attr("value");
			else
				selectIDs += ","+$(this).attr("value");
   		}
	})
	return selectIDs;
}
function ExecuteJsonData(oJsonUrl, oTemplateUrl, oDiv, oFileName, oPluginName, oFileType)
{
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"time="+(new Date().getTime()),
		url:        oJsonUrl,
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			$("#"+oDiv).setTemplateURL(oTemplateUrl+"?time="+(new Date().getTime()), null, {filter_data: true});
			$("#"+oDiv).processTemplate(d);
			if(oFileName!=null)
			{
				SaveHtml2File($("#"+oDiv).html(), oFileName, oPluginName, oFileType);
			}
		}
	});
}
function ExecuteTemplate(oJsonData, oTemplateUrl, oDiv, oFileName, oPluginName, oFileType)
{
	$("#"+oDiv).setTemplateURL(oTemplateUrl+"?time="+(new Date().getTime()), null, {filter_data: true});
	$("#"+oDiv).processTemplate(oJsonData);
	if(oFileName!=null)
	{
		SaveHtml2File($("#"+oDiv).html(), oFileName, oPluginName, oFileType);
	}
}
function SaveHtml2File(oHtml, oFileName, oPluginName, oFileType)
{
	if(oPluginName==null) oPluginName="";
	$.ajax({
		type:		"post",
		dataType:	"json",
		data:		"html="+encodeURIComponent(HTML2LowerCase(oHtml))+"&filename="+oFileName+"&filetype="+oFileType+"&pluginname="+oPluginName+"&time="+(new Date().getTime()),
		url:		site.Dir + "ajax/html2file.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success: function(){}
	});
}
function ajaxPluginTopNav(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxPluginTopNav";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_topnav.htm", oDiv, site.Dir + "_data/style/j_topnav.js", "", "js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_topnav.htm", oDiv, site.Dir + "_data/html/j_topnav.htm", "", "html");
	else
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_topnav.htm", oDiv);
}
function ajaxPluginRssMap(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxPluginRssMap";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_rssmap.htm", oDiv, site.Dir + "_data/style/j_rssmap.js", "", "js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_rssmap.htm", oDiv, site.Dir + "_data/html/j_rssmap.htm", "", "html");
	else
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_rssmap.htm", oDiv);
}
function ajaxPluginSiteMap(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxPluginSiteMap";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_sitemap.htm", oDiv, site.Dir + "_data/style/j_sitemap.js", "", "js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_sitemap.htm", oDiv, site.Dir + "_data/html/j_sitemap.htm", "", "html");
	else
		ExecuteTemplate($$_JSON_SystemTree, site.Dir + "templates/_sitemap.htm", oDiv);
}
function ajaxPluginTopNavStuHover() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var topnavbar = document.getElementById("topnavbar");
	if(topnavbar != null)
	{
		var getElm = topnavbar.getElementsByTagName("LI");
		for (var i=0; i<getElm.length; i++) {
			getElm[i].onmouseover=function() {
				this.className+=" iehover";
			}
			getElm[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
}
function ajaxAddMessage(userid,username){
	window.open(site.Dir + 'user/pmsend/index.aspx?touserid='+userid+'&tousername='+escape(username));
}
function ajaxAddFriend(userid){
	$.ajax({
		type:		"post",
		dataType:	"json",
		data:		"id="+userid+"&time="+(new Date().getTime()),
		url:		site.Dir + "user/friendadd/ajax.aspx?oper=ajaxAddFriend",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			switch (d.result)
			{
			case '0':
				alert(d.returnval);
				break;
			case '1':
				alert(d.returnval);
				break;
			}
		}
	});
}
function ajaxCopyright(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxCopyright";
	if(save2file=="js")
		ExecuteTemplate($$_JSON_Site, site.Dir + "templates/_copyright.htm", oDiv, site.Dir + "_data/style/j_copyright.js","","js");
	else if(save2file=="html")
		ExecuteTemplate($$_JSON_Site, site.Dir + "templates/_copyright.htm", oDiv, site.Dir + "_data/html/j_copyright.htm","","html");
	else
		ExecuteTemplate($$_JSON_Site, site.Dir + "templates/_copyright.htm", oDiv);
}
/*显示会员主页*/
function ShowUserPage(userid){
	//alert(userid);
}


/*========================================================================================*/
function UrlSearch(){ //重复时只取最后一个
	var name,value; 
	var str=window.location.href; //取得整个地址栏
	var num=str.indexOf("?") 
	str=str.substr(num+1); //取得所有参数
	var arr=str.split("&"); //各个参数放到数组里
	for(var i=0;i < arr.length;i++){ 
		num=arr[i].indexOf("="); 
		if(num>0){ 
			name=arr[i].substring(0,num);
			value=arr[i].substr(num+1);
			this[name]=value;
		} 
	}
	this["getall"]=str;
}
var RQ=new UrlSearch(); //实例化
function formatStr(s){
	if(typeof(s) == "string")
		return s;
	else
		return "";
}
function joinValue(parameter){
	eval("var temp=RQ."+parameter);
	if((typeof(temp) == "string") && (typeof(temp) != null))
	{
		return "&"+parameter+"="+temp.replace(/(^\s*)|(\s*$)/g, "");
	}
	else
		return "";
}
/*
function q(parameter){
	eval("var temp=RQ."+parameter);
	if((typeof(temp) == "string") && (typeof(temp) != null))
	{
		return temp.replace(/(^\s*)|(\s*$)/g, "");
	}
	else
		return "";
}
*/
function q(pname){
	var query = location.search.substring(1);
	var qq = "";
	params = query.split("&");
	if(params.length>0){
		for(var n in params){
			var pairs = params[n].split("=");
			if(pairs[0]==pname){
				qq = pairs[1];
				break;
			}
		}
	}
	return qq;
}
function anchor(){
	var str=window.location.href; //取得整个地址栏
	var num=str.indexOf("#") 
	str=str.substr(num+1);
	return str;
}
/*获取当前页页码*/
function thispage(){
	var r = /^\+?[1-9][0-9]*$/;
	if(r.test(q('page')))
		return q('page');
	else
		return "1";
}
/*全选*/
function CheckAll(form)
{
	var f;
	if(form==null)
		f = document.getElementsByTagName('FORM')[0];
	else
		f = document.getElementById(form);
	for (var i=0;i<f.elements.length;i++)
	{
		var e = f.elements[i];
		if (e.name != 'chkall' && e.type == "checkbox")
			e.checked = document.getElementById("chkall").checked;
	}
}
/*全不选*/
function CheckNo(form)
{
	var f;
	if(form==null)
		f = document.getElementsByTagName('FORM')[0];
	else
		f = document.getElementById(form);
	for (var i=0;i<f.elements.length;i++)
	{
		var e = f.elements[i];
		if (e.type == "checkbox")
			e.checked = false;
	}
}
function WinFullOpen(url){
	var newwin=window.open(url,"","scrollbars");
	if(document.all){
		newwin.moveTo(0,0);
		newwin.resizeTo(screen.width,screen.height);
	}
}
function WindowOpen(url,iWidth,iHeight,name)
{
	if(name==null) name='';
	var iTop = (window.screen.availHeight-30-iHeight)/2;
	var iLeft = (window.screen.availWidth-10-iWidth)/2;
	window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}
function tabit(btn){
	var idname = new String(btn.id);
	var s = idname.indexOf("_");
	var e = idname.lastIndexOf("_")+1;
	var tabName = idname.substr(0, s);
	var id = parseInt(idname.substr(e, 1));
	var tabNumber = btn.parentNode.childNodes.length;
	for(i=0;i<tabNumber;i++)
	{
		document.getElementById(tabName+"_div_"+i).style.display = "none"; 
		document.getElementById(tabName+"_btn_"+i).className = "none";
        
	}	
	document.getElementById(tabName+"_div_"+id).style.display = "block"; 
	btn.className = "curr";
}
var fodTime;
function delaytabit(btn){
	clearTimeout(fodTime);
	fodTime=setTimeout(function(){tabit(btn)},100);
}
/*字符串格式化*/
String.prototype.Trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.LTrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.RTrim = function(){return this.replace(/(\s*$)/g, "");}
/*日期格式化(2009-06-30+++)*/
function formatDate(strDate, format){
	return parseDate(strDate).format(format);
} 
Date.prototype.format = function(format)
{
	if(format == null) format = "yyyy-MM-dd hh:mm:ss";
	var o = 
	{
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(),    //day
		"h+" : this.getHours(),   //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter
		"S" : this.getMilliseconds() //millisecond
	}
		
	if(/(y+)/.test(format)) 
		format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	return format;
}
function parseDate(str){   
	if(typeof str == 'string'){   
		var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);   
		if(results && results.length>3)   
			return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]));    
		results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);   
		if(results && results.length>6)   
			return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]));    
		results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);   
		if(results && results.length>7)   
			return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]),parseInt(results[7]));    
	}   
	return null;   
}
/*预览HTML代码*/
function PreviewHTML(txt)
{
	var win = window.open("", "win");
	win.document.open("text/html", "replace"); 
	win.document.write(txt); 
	win.document.close();
}
/*格式化列表*/
function FormatListValue(id)
{
	var _val = $('#'+id).val();
	if(_val=='') return;
	_val =_val.replace(/[，]/g,",");
	_val =_val.replace(/ /g,",");
	_val =_val.replace(/[,]+/g,",");
	$('#'+id).val(_val);
}
function PlayCodeVoice(wmpid)
{
	if(wmpid==null) wmpid="player";
	var _voicewmp2 = $$(wmpid);
	var _voicecode = ReadCookie("ValidateCode");
	_voicewmp2.innerHTML = "<embed id='sound_play' name='sound_play' src='" + site.Dir + "publicstyle/sound_play.swf?"+(new Date().getTime())+"' FlashVars='isPlay=1&url=" + site.Dir + "plus/codevoice.aspx&code=" + _voicecode + "' width='0' height='0' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}